package com.whpu.mall.ware.config;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    //hutool工具包将日期格式化
    Date date = DateUtil.parse(DateUtil.now());

    //fill = FieldFill.INSERT时调用此方法填充
    public void insertFill(MetaObject metaObject) {


        //要填充的字段名/值/metaObject
        this.setFieldValByName("createTime", new Date(),metaObject);
        this.setFieldValByName("updateTime", new Date(),metaObject);
    }

    //fill = FieldFill.UPDATE时调用此方法填充
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("updateTime",new Date(),metaObject);
    }
}
